#include <func.h>

int my_pwd(int id,char *buf_to_store_path,MYSQL* mysql){
    
char sql[1024]={0};

sprintf(sql,"select path from file_tbl where id = %d;",id);

int qret=mysql_query(mysql,sql);
if(qret!=0){
fprintf(stderr,"SQL statement error : %s\n",mysql_error(mysql));
}

MYSQL_RES* result = mysql_store_result(mysql);
MYSQL_ROW row;
row=mysql_fetch_row(result);

buf_to_store_path=row[0];

return 0;
}

int my_mkdir(char* dir_name,char* pwd,char* user_name,int id,MYSQL* mysql){

char sql[1024]={0};

sprintf(sql,"insert into file_tbl (filename,user_name,pre_id,type,path,is_delete,md5)" 
       "values('%s','%s',%d,'dir','%s',0,'0');",dir_name,user_name,id,pwd);
int qret=mysql_query(mysql,sql);
if(qret!=0){
fprintf(stderr,"SQL statement error : %s\n",mysql_error(mysql));
}

return 0;
}

int my_rm(char* filename,char* pwd,char* user_name,MYSQL* mysql){
    
char sql[1024]={0};
sprintf(sql,"delete from file_tbl where filename='%s' and path='%s' and user_name='%s';",filename,pwd,user_name);
int qret=mysql_query(mysql,sql);
if(qret!=0){
fprintf(stderr,"SQL statement error : %s\n",mysql_error(mysql));
}

return 0;
}

int my_rmdir(char* filename,char* pwd,char* user_name,int id,MYSQL* mysql){
char sql[1024]={0};
sprintf(sql,"select * from file_tbl where pre_id= %d;",id);
int qret=mysql_query(mysql,sql);
if(qret!=0){
fprintf(stderr,"SQL statement error : %s\n",mysql_error(mysql));
}
MYSQL_RES* result = mysql_store_result(mysql);
MYSQL_ROW row;
row=mysql_fetch_row(result);
if(row!=NULL){
    return -1;
}

bzero(sql,sizeof(sql));
sprintf(sql,"delete from file_tbl where filename='%s' and path='%s' and user_name='%s';",filename,pwd,user_name);
qret=mysql_query(mysql,sql);
if(qret!=0){
fprintf(stderr,"SQL statement error : %s\n",mysql_error(mysql));
}

return 0;

}
